//
//  UserStore.m
//  HelloWorld
//
//  Created by Martin Le C. on 5/15/09.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import "UserStore.h"


@implementation UserStore
@synthesize users;
-(id)init {
	self.users = [NSMutableDictionary dictionaryWithCapacity:1];
	return self;
}
-(BOOL) contains:(NSString*)id {
	if ([self.users objectForKey:id] == nil)
		return NO;
	else 
		return YES;
}
-(YahooUser*) get:(NSString*)id {
	return (YahooUser*)[self.users objectForKey:id];
}
-(YahooUser*) getOrCreate:(NSString*)id {
	if(![self contains:id]) [self.users setObject:[[YahooUser alloc] init:id] forKey:id];
	return [self get:id];
}

// Get and update a user object, or create if not known already 
-(YahooUser*) getOrCreate:(NSString*)id st:(NSString*)st ch:(NSString*)ch pg:(NSString*) pg {
	if(![self contains:id])  [self.users setObject:[[YahooUser alloc] init:id st:st ch:ch pig:pg] forKey:id];
	else [[self get:id] update:id st:st ch:ch pig:pg];
	return [self get:id];
}
@end